package com.hwua.tonyshop.controller.bg;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hwua.tonyshop.criteria.GoodsClassCriteria;
import com.hwua.tonyshop.criteria.MenuInfoCriteria;
import com.hwua.tonyshop.entity.mojo.GoodsClassAO;
import com.hwua.tonyshop.entity.mojo.MenuInfoAO;
import com.hwua.tonyshop.entity.pojo.GoodsClass;
import com.hwua.tonyshop.entity.pojo.MenuInfo;
import com.hwua.tonyshop.service.IGoodsClassService;
import com.slkj.autocode.entity.ServiceResult;
import com.slkj.autocode.util.DateTimeUtils;
/**
 * 
 * @author sunny Yang
 * @date 2018年5月24日
 * @discribe
 * 商品分类管理
 *
 */
@Controller
@RequestMapping(value = "/back/goodsClass")
public class GoodsClassManagerController {
	@Resource
	IGoodsClassService goodsClassService;
		/**
		 * 跳转到商品分类管理页面
		 * @param model
		 * @param request
		 * @param response
		 * @return
		 */
		@RequestMapping(value = "/toGoodsClassPage", method = { RequestMethod.GET, RequestMethod.POST })
		public String toGoodsClassPage(Model model,HttpServletRequest request,HttpServletResponse response) {
		  	
			return "background/goods_class_index";
		}
		@RequestMapping(value = "/toGoodsClassNewPage", method = { RequestMethod.GET, RequestMethod.POST })
		public String toGoodsClassNewPage(Model model,HttpServletRequest request,HttpServletResponse response) {
		  	
			return "background/class_goods_new";
		}

		@RequestMapping(value = "/getGoodsClass", method = { RequestMethod.GET, RequestMethod.POST })
		@ResponseBody
		public ServiceResult<GoodsClassAO> getGoodsClass(Integer goodsClassId,String backToken,Model model,HttpServletRequest request,HttpServletResponse response) {
			return goodsClassService.selectById(goodsClassId);
		}
		
		@RequestMapping(value = "/getGoodsClasses", method = { RequestMethod.GET, RequestMethod.POST })
		@ResponseBody
		public ServiceResult<List<GoodsClassAO>> getGoodsClasses(Model model,HttpServletRequest request,HttpServletResponse response) {
			GoodsClassCriteria criteria = new GoodsClassCriteria();
			return goodsClassService.selectByCriteria(criteria);
		}
		
		@RequestMapping(value = "/deleteGoodsClass", method = { RequestMethod.GET, RequestMethod.POST })
		@ResponseBody
		public ServiceResult<Integer> deleteGoodsClass(Integer goodsClassId,String backToken,Model model,HttpServletRequest request,HttpServletResponse response) {
			return goodsClassService.deleteById(goodsClassId);
		}
		
		@RequestMapping(value = "/addGoodsClass", method = { RequestMethod.GET, RequestMethod.POST })
		@ResponseBody
		public ServiceResult<Integer> addGoodsClass(GoodsClass goodsClass,String backToken,Model model,HttpServletRequest request,HttpServletResponse response) {
			goodsClass.setState("0");
			goodsClass.setCreateDate(DateTimeUtils.formateDateToStr(new Date()));
			return goodsClassService.addGoodsClass(goodsClass);
		}
		
		@RequestMapping(value = "/updateGoodsClass", method = { RequestMethod.GET, RequestMethod.POST })
		@ResponseBody
		public ServiceResult<Integer> updateGoodsClass(GoodsClass goodsClass,String backToken,Model model,HttpServletRequest request,HttpServletResponse response) {
			return goodsClassService.updateById(goodsClass);
		}
}
